package com.itrip.biz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itrip.beans.pojo.Image;
import com.itrip.beans.vo.ItripImageVO;
import com.itrip.dao.ImageMapper;
import com.itrip.utils.dto.Dto;
import com.itrip.utils.vo.DtoUtil;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/biz/api/hotel")
public class HotelCommentController {
    @Resource
    ImageMapper imageMapper;
    @RequestMapping(value = "/getimg/{targetId}")
    public Dto<Object> getImgByTargetId(@PathVariable String targetId) {
        Dto<Object> dto = new Dto<Object>();
        if (null != targetId && !"".equals(targetId)) {
            QueryWrapper<Image> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("type",0);
            queryWrapper.eq("target_id", targetId);
            try {
                List<Image> images = imageMapper.selectList(queryWrapper);
                ItripImageVO itripImageVO =new ItripImageVO();
                for (int i = 0; i < images.size(); i++) {
                    Image s = (Image) images.get(i);
                    itripImageVO.setImgUrl(s.getImgUrl());
                    itripImageVO.setPosition(s.getPosition());
                }
                dto = DtoUtil.returnSuccess("获取酒店图片成功", itripImageVO);
            } catch (Exception e) {
                e.printStackTrace();
                dto = DtoUtil.returnFail("获取酒店图片失败");
            }
        } else {
            dto = DtoUtil.returnFail("酒店id不能为空");
        }
        return dto;
    }
}
